package com.ui;

import javax.swing.*;
import java.awt.event.*;

public class ALL_x extends JDialog {
    private JPanel contentPane;
    private JButton buttonOK;
    private JButton buttonCancel;
    private JList list1;

    public ALL_x() {
        setContentPane(contentPane);
        setModal(true);
        getRootPane().setDefaultButton(buttonOK);

        buttonOK.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onOK();
            }
        });

        buttonCancel.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onCancel();
            }
        });

        // 点击 X 时调用 onCancel()
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                onCancel();
            }
        });

        // 遇到 ESCAPE 时调用 onCancel()
        contentPane.registerKeyboardAction(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onCancel();
            }
        }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    }

    private void onOK() {
        // 在此处添加您的代码
        //点击此按钮时从数据库读入所有商品信息
        DENGLU.c.goods.clear();
        for(int i=1;i<50;i++)
        {
            DENGLU.c.process(DENGLU.c.CheckGood(i));
        }
        String[] lst=new String[DENGLU.c.goods.size()+1];
        lst[0]="商品        商品号        价格        数量";
        for(int i=1;i<=DENGLU.c.goods.size();i++)
        {
            lst[i]=DENGLU.c.goods.get(i-1).getName()+"        "+DENGLU.c.goods.get(i-1).getID()+"        "+DENGLU.c.goods.get(i-1).getprice()+"        "+DENGLU.c.goods.get(i-1).getNum();
        }

       list1.setListData(lst);

        //JScrollPane scrollPane=new JScrollPane(list1);
    }

    private void onCancel() {
        // 必要时在此处添加您的代码
        dispose();
    }

    public void main() {
        ALL_x dialog = new ALL_x();
        dialog.pack();
        dialog.setVisible(true);
        //System.exit(0);
    }
}
